#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //创建6个按钮按照2*3方式排列
    QPushButton* button1=new QPushButton("按钮1");
    QPushButton* button2=new QPushButton("按钮2");
    QPushButton* button3=new QPushButton("按钮3");
    QPushButton* button4=new QPushButton("按钮4");
    QPushButton* button5=new QPushButton("按钮5");
    QPushButton* button6=new QPushButton("按钮6");
    //创建布局并添加
    QGridLayout* layout=new QGridLayout();
    this->setLayout(layout);
    layout->addWidget(button1,0,0);
    layout->addWidget(button2,0,1);
    layout->addWidget(button3,0,2);
    layout->addWidget(button4,1,0);
    layout->addWidget(button5,1,1);
    layout->addWidget(button6,1,2);

    //设置水平方向拉伸系数1:1:2,如果拉伸系数设为0,则该列按钮不参与拉伸
    layout->setColumnStretch(0,1);
    layout->setColumnStretch(1,1);
    layout->setColumnStretch(2,2);
}

Widget::~Widget()
{
    delete ui;
}

